package com.baoli.umpush.util;

import com.baoli.umpush.common.PushClient;
import com.baoli.umpush.pojo.MsgBody;
import com.baoli.umpush.push.android.AndroidBroadcast;
import com.baoli.umpush.push.android.AndroidListcast;
import com.baoli.umpush.push.android.AndroidUnicast;

public class AndroidUmengUtils {
    private String appkey;

    private String appMasterSecret;

    private PushClient client = new PushClient();

    public AndroidUmengUtils() {

    }

    public AndroidUmengUtils(String key, String secret) {
        this.appkey = key;
        this.appMasterSecret = secret;
    }

    /**
     * 单播
     */
    public String sendAndroidUnicast(MsgBody umengMsg, String deviceToken) throws Exception {
        AndroidUnicast unicast = new AndroidUnicast(appkey, appMasterSecret, umengMsg, deviceToken);
        return client.send(unicast);
    }

    /**
     * 列播
     *
     * @param deviceTokens 多个使用','分隔
     */
    public String sendAndroidListcast(MsgBody umengMsg, String deviceTokens) throws Exception {
        AndroidListcast listcast = new AndroidListcast(appkey, appMasterSecret, umengMsg, deviceTokens);
        return client.send(listcast);
    }

    /**
     * 文件播，每小时可推送300次
     *
     * @param deviceTokens 多个使用'\n'分隔
     */
   /* public String sendAndroidFilecast(MsgBody umengMsg, String deviceTokens) throws Exception {
        // 上传文件
        String fileId = client.uploadContents(appkey, appMasterSecret, deviceTokens);
        AndroidFilecast filecast = new AndroidFilecast(appkey, appMasterSecret, umengMsg);
        filecast.setFileId(fileId);

        return client.send(filecast);
    }*/

    /**
     * 广播，给所有安卓APP发送推送，每天可推送10次
     */
    public String sendAndroidBroadcast(MsgBody umengMsg) throws Exception {
        AndroidBroadcast broadcast = new AndroidBroadcast(appkey, appMasterSecret, umengMsg);
        return client.send(broadcast);
    }

    /**
     * 组播，按照filter筛选用户群，每分钟可推送5次
     */
   /* @SuppressWarnings("unused")
    private String sendAndroidGroupcast(MsgBody umengMsg) throws Exception {
        AndroidGroupcast groupcast = new AndroidGroupcast(appkey, appMasterSecret, umengMsg);
        JSONObject filterJson = new JSONObject();
        JSONObject whereJson = new JSONObject();
        JSONArray tagArray = new JSONArray();
        JSONObject testTag = new JSONObject();
        JSONObject TestTag = new JSONObject();
        testTag.put("tag", "test");
        TestTag.put("tag", "Test");
        tagArray.add(testTag);
        tagArray.add(TestTag);
        whereJson.put("and", tagArray);
        filterJson.put("where", whereJson);
        //        System.out.println(filterJson.toString());

        groupcast.setFilter(filterJson);

        return client.send(groupcast);
    }
*/
    /**
     * 通过alias，对单个或者多个alias进行推送
     * alias的类型, alias_type可由开发者自定义, 开发者在SDK中 调用setAlias(alias, alias_type)时所设置的alias_type
     */
   /* @SuppressWarnings("unused")
    private String sendAndroidCustomizedcast(MsgBody umengMsg) throws Exception {
        AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey, appMasterSecret, umengMsg);
        // TODO Set your alias here, and use comma to split them if there are multiple alias.
        // And if you have many alias, you can also upload a file containing these alias, then
        // use file_id to send customized notification.
        customizedcast.setAlias("alias", "alias_type");

        return client.send(customizedcast);
    }
*/
    /**
     * 将alias存放到文件后，根据file_id来推送 每小时可推送300次
     */
   /* @SuppressWarnings("unused")
    private String sendAndroidCustomizedcastFile(MsgBody umengMsg) throws Exception {
        AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey, appMasterSecret, umengMsg);
        // TODO Set your alias here, and use comma to split them if there are multiple alias.
        // And if you have many alias, you can also upload a file containing these alias, then
        // use file_id to send customized notification.
        String fileId = client.uploadContents(appkey, appMasterSecret, "aa" + "\n" + "bb" + "\n" + "alias");
        customizedcast.setFileId(fileId, "alias_type");

        return client.send(customizedcast);
    }*/
}
